package com.barunsw.bwf.neoarena_erp.repair_order;

import java.util.List;
import java.util.Locale;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.barunsw.bwf.neoarena_erp.vo.CustomerAccountVo;
import com.barunsw.bwf.neoarena_erp.vo.RepairOrderVo;

@Controller
@RequestMapping("/repair_order_retrieve")
public class RepairOrderRetrieveController {
	private static final Logger logger = LoggerFactory.getLogger(RepairOrderRetrieveController.class);
	
	@Autowired
	private RepairOrderService repairOrderService;
	
	@RequestMapping(value = "/view", method = RequestMethod.GET)
	public String home(Locale locale, Model model) {
		return "repair_order/repair_order_retrieve";
	}
	
	@RequestMapping(value = "/dhtmlx", method = RequestMethod.GET)
	public String home2(Locale locale, Model model) {
		logger.debug("dhtmlx");
		
		return "dhtmlx/repair_order/repair_order_retrieve";
	}
	
	@RequestMapping(value = "", method = RequestMethod.GET)
	public @ResponseBody List<RepairOrderVo> list(
			@RequestBody @RequestParam(value="accountNumber", required=false) String accountNumber,
			@RequestBody @RequestParam(value="orderNo", required=false) String orderNo,
			@RequestBody @RequestParam(value="serialNo", required=false) String serialNo
			) throws Exception {
		logger.debug(String.format("list?accountNumber=%s&orderNo=%s&serialNo=%s", accountNumber, orderNo, serialNo));
		
		RepairOrderVo repairOrderVo = new RepairOrderVo();
		repairOrderVo.setAccountNumber(accountNumber);
		repairOrderVo.setRoHeaderId(orderNo);
		repairOrderVo.setSerialNo(serialNo);
		
		List<RepairOrderVo> repairOrderList = repairOrderService.selectList(repairOrderVo);
		
		return repairOrderList;
	}
}
